#ifndef __MYSQL_CONN_H__
#define __MYSQL_CONN_H__

#include "mysql.h"
#include <iostream>
#include "TableData.h"


typedef enum
{
	MYSQL_CONN_IDLE,
	MYSQL_CONN_BUSY,
}MYSQL_CONN_STATE;

class CMysqlConn
{
public:
	CMysqlConn(char* url, char* user, char* password, char* dbname, unsigned int port);
	~CMysqlConn();

	void InitConn();
	bool Connect();
	bool Reconnect();
	bool CheckConnection();
	void CloseConnect();
	MYSQL_CONN_STATE GetConnectionState();
	unsigned int QuerySQL(char* pStrSql, CTableData* pTableData);
	unsigned int ExcuteSQL(char* pStrSql);
private:
	MYSQL* m_pstMysql;

	std::string m_strDbUrl;
	std::string m_strDbUser;
	std::string m_strDbPassword;
	std::string m_strDbName;
	unsigned int m_iDbPort;

	bool m_bIsConnected;
	MYSQL_CONN_STATE m_State;

	CTableData* m_pDataManager;
};

#endif //__MYSQL_CONN_H__